package com.TeacherInfoServer.mapper;

import com.TeacherInfoServer.pojo.DTO.SearchDTO.TitleHistorySearchDTO;
import com.TeacherInfoServer.pojo.entity.TitleHistory;
import com.TeacherInfoServer.pojo.vo.TitleHistoryVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TitleHistoryMapper extends BaseMapper<TitleHistory> {
    List<TitleHistory> selectPageWithTeacher(Page<TitleHistory> page);

    @Select("<script>" +
            "SELECT th.*, t.teacher_name, ti.value as titleLevel " +
            "FROM title_history th " +
            "LEFT JOIN teacher t ON th.teacher_id = t.teacher_id " +
            "LEFT JOIN type_info ti ON th.title_level_id = ti.id " +
            "<where> " +
            "<if test='search.teacherId != null and search.teacherId.trim() != \"\"'> " +
            "AND th.teacher_id LIKE CONCAT('%', #{search.teacherId}, '%') " +
            "</if> " +
            "<if test='search.teacherName != null and search.teacherName.trim() != \"\"'> " +
            "AND t.teacher_name LIKE CONCAT('%', #{search.teacherName}, '%') " +
            "</if> " +
            "<if test='search.titleLevel != null and search.titleLevel.trim() != \"\"'> " +
            "AND tl.value LIKE CONCAT('%', #{search.titleLevel}, '%') " +
            "</if> " +
            "<if test='search.obtainDate != null and search.obtainDate.trim() != \"\"'> " +
            "AND th.obtain_date LIKE CONCAT ('%', #{search.obtainDate}, '%') " +
            "</if> " +
            "<if test='search.isCurrentTitle != null and search.isCurrentTitle.trim() != \"\"'> " +
            "AND th.is_current_title LIKE CONCAT('%', #{search.isCurrentTitle}, '%') " +
            "</if> " +
            "</where> " +
            "ORDER BY th.teacher_id ASC, th.title_level_id DESC" +
            "</script>")
    Page<TitleHistoryVo> searchTitleHistoryList(Page<?> page, @Param("search") TitleHistorySearchDTO search);

}
